export
default class {
        constructor(items) {
            this.total = this.getTotal(items);
            this.money = this.getMoney(items);
            this.totalMoney = this.getTotalMoney();
            this.stock = this.getStock(items)
        }
        getTotal(items) {
            let numArr = items.map(function(item) {
                return item.num
            });
            return numArr.reduce(function(acc, cur) {
                return acc + cur
            })
        }
        getMoney(items) {
            return items.map(function(item) {
                return item.num * item.price
            })
        }
        getTotalMoney() {
            return this.money.reduce(function(acc, cur) {
                return acc + cur
            })
        }
        getStock(items) {
            return items.map(function(item) {
                let currentstock = item.stock - item.num;
                if (currentstock < 0) {
                    currentstock = 0
                }
                return currentstock
            })
        }
    }